import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class HomeBannerView extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _HomeBannerViewState();
  }
}

class _HomeBannerViewState extends State<HomeBannerView>
    with SingleTickerProviderStateMixin {
  SwiperController _swiperController;

  @override
  void initState() {
    // TODO: implement initState
    _swiperController = SwiperController();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      height: 160,
      margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15),
      child: ClipRRect(
        borderRadius: BorderRadius.all(Radius.circular(8)),
        child: Swiper(
          itemBuilder: (BuildContext context, int index) {
            return CachedNetworkImage(
              imageUrl:
                  'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwx1.sinaimg.cn%2Flarge%2F008fHVgdly4gqfhftvhl5j30u00iv40g.jpg&refer=http%3A%2F%2Fwx1.sinaimg.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1625727167&t=6f02868aba5632a713a473d32372252d',
              placeholder: (context, url) => Image.asset(
                'assets/images/banner.png',
                fit: BoxFit.fill,
              ),
              errorWidget: (context, url, error) => Image.asset(
                'assets/images/banner.png',
                fit: BoxFit.fill,
              ),
              fit: BoxFit.fill,
            );
          },
          itemCount: 3,
          autoplay: true,
          controller: _swiperController,
          pagination: new SwiperPagination(
            builder: DotSwiperPaginationBuilder(
              size: 7,
              activeSize: 7,
              color: Colors.black54,
              activeColor: Colors.white,
            ),
          ),
        ),
      ),
    );
  }
}
